package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexSearchVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    // /api/search/albumInfo/upperAlbum/{albumId}
    //上架专辑
    @GetMapping("upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable(value = "albumId") Long albumId) {
        searchService.upperAlbum(albumId);
        return Result.ok();
    }

    // /api/search/albumInfo/lowerAlbum/{albumId}
    //下架专辑
    @GetMapping("/lowerAlbum/{albumId}")
    public Result getLower(@PathVariable Long albumId) {
        searchService.getLower(albumId);
        return Result.ok();
    }

    @Operation(summary = "批量上架")
    @GetMapping("/batchUpperAblum")
    public Result upperAlbum() {
        for (long i = 2; i <= 1500; i++) {   // 专辑id为1数据补全，缺少专辑属性数据
            searchService.upperAlbum(i);
        }
        return Result.ok();
    }

    // /api/search/albumInfo
    //专辑列表搜索
    @PostMapping
    public Result<AlbumSearchResponseVo> searchAlbumInfo(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo albumSearchResponseVo = searchService.searchAlbumInfo(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

    // /api/search/albumInfo/channel/{category1Id}
    //获取频道页数据
    @GetMapping(value = "/channel/{category1Id}")
    public Result<List<AlbumInfoIndexSearchVo>> channel(@PathVariable(value = "category1Id") Long category1Id) {
        List<AlbumInfoIndexSearchVo> albumInfoIndexSearchVos =  searchService.channel(category1Id) ;
        return Result.ok(albumInfoIndexSearchVos) ;
    }

    // /api/search/albumInfo/completeSuggest/{keyword}
    //关键字自动补全功能
    @GetMapping(value = "/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable(value = "keyword") String keyword) {
        List<String> list = searchService.completeSuggest(keyword);
        return Result.ok(list) ;
    }

    // /api/search/albumInfo/updateLatelyAlbumRanking
    //更新排行榜
    @GetMapping(value = "/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok() ;
    }

    // /api/search/albumInfo/findRankingList/{category1Id}/{dimension}
    //获取排行榜列表
    @GetMapping("findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndex>> findRankingList(@PathVariable Long category1Id, @PathVariable String dimension){
       List<AlbumInfoIndex> albumInfoIndexVoList =  searchService.findRankingList(category1Id,dimension);
       return Result.ok(albumInfoIndexVoList);
    }
}

